//Sat Jun  4 02:11:16 CDT 2011
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>

using namespace std;

class Time{
public:
	int h;
	int m;
	Time(int a, int b){
		h = a;
		m = b;
	}
	static bool cmp(const Time &A, const Time &B){
		if(A.h > B. h) return true;
		if(A.h == B.h && A.m > B.m) return true;
		return false;
	}
};

class Cafeteria {
public:
	string latestTime(vector <int>, vector <int>, vector <int>);
};

string Cafeteria::latestTime(vector <int> offset, vector <int> walkingTime, vector <int> drivingTime) {
	vector<Time> res;
	int N = offset.size();
	for(int i=0; i<N; i++){
		int hr = 14;
		int min = 30;
		min -= drivingTime[i];
		while(min < 0){
			min += 60;
			hr --;
		}
		if(min < offset[i]) {
			min += 60;
			hr --;
		}
		while(min >= offset[i]){
			offset[i] += 10;
		}
		min = offset[i] - 10;
		min -= walkingTime[i];
		if(min < 0){
			min += 60;
			hr --;
		}
		res.push_back(Time(hr, min));
	}
	sort(res.begin(), res.end(), Time::cmp);
	char ch[10];
	sprintf(ch, "%02d:%02d", res[0].h>12?res[0].h-12:res[0].h, res[0].m);
	return string(ch);
}

//<%:testing-code%>
//Powered by [KawigiEdit] 2.0!
